<template>
    <div class="xiaohui-list">
        <div class="page-header">
            <div class="header-content">
                <router-link to="/main/biao/xiaohui" class="back-link">
                    <i class="el-icon-arrow-left"></i>返回
                </router-link>
                <h2>文件销毁申请单列表</h2>
            </div>
            <div class="header-actions">
                <el-input
                    v-model="searchKeyword"
                    placeholder="请输入关键字搜索"
                    class="search-input"
                    clearable
                    @clear="handleSearch"
                    @keyup.enter.native="handleSearch">
                    <el-button slot="append" icon="el-icon-search" @click="handleSearch"></el-button>
                </el-input>
                <el-button type="primary" icon="el-icon-plus" @click="handleAdd">新增申请单</el-button>
            </div>
        </div>

        <el-table
            v-loading="loading"
            :data="tableData"
            border
            style="width: 100%">
            <el-table-column
                prop="id"
                label="编号"
                width="80"
                align="center">
            </el-table-column>
            <el-table-column
                prop="destructionReason"
                label="销毁原因"
                show-overflow-tooltip>
            </el-table-column>
            <el-table-column
                prop="destructionDate"
                label="销毁日期"
                width="120"
                align="center">
                <template slot-scope="scope">
                    {{ scope.row.destructionDate ? new Date(scope.row.destructionDate).toLocaleDateString() : '' }}
                </template>
            </el-table-column>
            <el-table-column
                prop="handler"
                label="经办人"
                width="120"
                align="center">
            </el-table-column>
            <el-table-column
                prop="approver"
                label="批准人"
                width="120"
                align="center">
            </el-table-column>
            <el-table-column
                label="操作"
                width="300"
                align="center">
                <template slot-scope="scope">
                    <el-button
                        size="mini"
                        @click="handleView(scope.row)">查看</el-button>
                    <el-button
                        size="mini"
                        type="primary"
                        @click="handleEdit(scope.row)">编辑</el-button>
                    <el-button
                        size="mini"
                        type="danger"
                        @click="handleDelete(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <div class="pagination-container">
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import { getFileDestructionList, deleteFileDestruction } from '@/api/fileDestruction'

export default {
    name: 'XiaohuiList',
    data() {
        return {
            loading: false,
            searchKeyword: '',
            tableData: [],
            currentPage: 1,
            pageSize: 10,
            total: 0
        }
    },
    created() {
        this.fetchData()
    },
    methods: {
        async fetchData() {
            this.loading = true
            try {
                const res = await getFileDestructionList({
                    current: this.currentPage,
                    size: this.pageSize,
                    keyword: this.searchKeyword
                })
                this.tableData = res.data.records
                this.total = res.data.total
            } catch (error) {
                this.$message.error('获取数据失败')
            } finally {
                this.loading = false
            }
        },
        handleSearch() {
            this.currentPage = 1
            this.fetchData()
        },
        handleAdd() {
            this.$router.push('/main/biao/xiaohui')
        },
        handleView(row) {
            this.$router.push(`/main/biao/xiaohui?id=${row.id}&mode=view`)
        },
        handleEdit(row) {
            this.$router.push(`/main/biao/xiaohui?id=${row.id}&mode=edit`)
        },
        async handleDelete(row) {
            try {
                await this.$confirm('确认删除该申请单吗？', '提示', {
                    type: 'warning'
                })
                await deleteFileDestruction(row.id)
                this.$message.success('删除成功')
                this.fetchData()
            } catch (error) {
                if (error !== 'cancel') {
                    this.$message.error('删除失败')
                }
            }
        },
        handleSizeChange(val) {
            this.pageSize = val
            this.fetchData()
        },
        handleCurrentChange(val) {
            this.currentPage = val
            this.fetchData()
        }
    }
}
</script>

<style lang="scss" scoped>
.xiaohui-list {
    padding: 20px;
    // background-color: #f5f7fa;
    min-height: calc(100vh - 40px);

    .page-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 20px;
        background-color: #fff;
        padding: 16px 24px;
        border-radius: 8px;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);

        .header-content {
            display: flex;
            align-items: center;

            .back-link {
                color: #409EFF;
                text-decoration: none;
                margin-right: 20px;
                display: flex;
                align-items: center;
                font-size: 14px;
                transition: all 0.3s;

                &:hover {
                    opacity: 0.8;
                }

                i {
                    margin-right: 5px;
                }
            }

            h2 {
                margin: 0;
                font-size: 20px;
                font-weight: 500;
                color: #303133;
            }
        }

        .header-actions {
            display: flex;
            align-items: center;
            gap: 16px;

            .search-input {
                width: 300px;

                :deep(.el-input__inner) {
                    border-radius: 4px;
                    &:hover {
                        border-color: #409EFF;
                    }
                }

                :deep(.el-input-group__append) {
                    background-color: #409EFF;
                    border-color: #409EFF;
                    color: #fff;
                    padding: 0 15px;
                    .el-icon-search {
                        font-size: 16px;
                    }
                }
            }

            .el-button {
                padding: 9px 20px;
            }
        }
    }

    .el-table {
        background-color: #fff;
        border-radius: 8px;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
        margin-bottom: 20px;

        :deep(th) {
            background-color: #f5f7fa;
            color: #606266;
            font-weight: 600;
            padding: 12px 0;
        }

        :deep(td) {
            padding: 12px 0;
        }

        :deep(.el-button--mini) {
            padding: 6px 12px;
            &:not(:last-child) {
                margin-right: 8px;
            }
        }

        :deep(.el-button--danger) {
            margin-left: 8px;
        }
    }

    .pagination-container {
        background-color: #fff;
        padding: 16px 24px;
        border-radius: 8px;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
        display: flex;
        justify-content: flex-end;

        :deep(.el-pagination) {
            button {
                min-width: 32px;
                height: 32px;
                line-height: 32px;
                border-radius: 4px;
                &:not(:disabled):hover {
                    color: #409EFF;
                }
            }

            .el-pagination__total,
            .el-pagination__sizes {
                margin-right: 16px;
            }

            .el-select .el-input {
                width: 120px;
                margin: 0 8px;
            }

            .el-pagination__jump {
                margin-left: 16px;
            }
        }
    }

    @media screen and (max-width: 768px) {
        .page-header {
            flex-direction: column;
            align-items: stretch;
            gap: 16px;

            .header-actions {
                flex-direction: column;
                .search-input {
                    width: 100%;
                }
                .el-button {
                    width: 100%;
                }
            }
        }

        .el-table {
            :deep(.el-button--mini) {
                padding: 4px 8px;
                font-size: 12px;
            }
        }

        .pagination-container {
            :deep(.el-pagination) {
                .el-pagination__sizes {
                    display: none;
                }
            }
        }
    }
}
::v-deep .el-form-item {
  .el-form-item__content {
    margin-left: 0px !important;
  }
}
</style> 